package paint;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.util.Vector;

import player.snakeObject;

import tag.constants;

public class paintSnake implements constants{

	@SuppressWarnings("unchecked")
	public static void snake(Graphics2D g2, snakeObject snake) {

		float[][] coords = snake.getCoords();
		
		
		// draw GeneralPath (polyline)
		float x[] = coords[0];
		float y[] = coords[1];
		
		Vector generalPath = new Vector();
		GeneralPath body;
		GeneralPath head;

		body = new GeneralPath();
		head = new GeneralPath();
		
		body.moveTo(x[0], y[0]);
		body.lineTo(x[0], y[0]);
	    
	      
	    for(int i=1; i<x.length; i++){
	    	body.lineTo(x[i], y[i]);
	    }
	    
	    head.moveTo(x[x.length-1], y[y.length-1]);
	    
	    
	    head.lineTo(x[x.length-2], y[y.length-2]);
	    	
	    generalPath.addElement(body);
	    generalPath.addElement(head);
	      
	      
	      for (int i = 0; i < generalPath.size(); i++) {
	    	  
	         
	         
		          if(i==generalPath.size()-1){
		        	  g2.setPaint(head_color);
		              g2.setStroke(new BasicStroke(cell_size-1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,30));  
			          g2.draw((GeneralPath) generalPath.elementAt(i));  
		          }
		          
		          else{
		        	  g2.setPaint(head_color);
		        	  g2.setStroke(new BasicStroke(cell_size-1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 30, new float[]{cell_size*2,cell_size*0.75f}, 0));
			          g2.draw((GeneralPath) generalPath.elementAt(i));
		        	  g2.setPaint(cell_color);
		              g2.setStroke(new BasicStroke(cell_size-1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 30, new float[]{cell_size*2,cell_size*1.25f}, 0));  
			          g2.draw((GeneralPath) generalPath.elementAt(i));
		      }
	          
	          
	        }  
	      
		
	}

}
